{-
    pHaskell Translator v0.1 
    Copyright (C) 2009  Ruben Marcelo Caro 

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
-}
module LambdaTypeDeduction where
import LambdaTypes
 	 
--Busca el tipo de una variable en un contexto
--si la variable no existe debuelve LtUnknown
lambdaLookupContext name ([]) = LtUnknown
lambdaLookupContext name ((n,t):xs) 	| name == n = t
										| otherwise = lambdaLookupContext name xs
								
--Sistema de inferencia de tipo
beta e = beta' e []
beta' (LInteger number) context = LtInt
beta' (LBoolean number) context = LtBool
beta' (LVariable var)   context = lambdaLookupContext var context
beta' (LApp e e1)       context = theta'
									where
										fullType = beta' e context
										theta'   = ldestinationType fullType
										--todo: se tiene que cumplir ademas 
										--beta' e1 context == lsourceType fullType

beta' (LLambda (LVariable v) theta e )  context = LtArrow theta theta'
										where
											theta' = beta' e ((v,theta):context)
											
beta' (LLambda  e1 theta e )  context = beta' e context
										




